//
//  ScrollMsg.m
//  Paoma
//
//  Created by longzhiyuan on 15/6/29.
//
//

#import "ScrollMsgScrollView.h"

@implementation ScrollMsgScrollView
-(instancetype)init
{
    if (self = [super init])
    {
        _nsIntSpeed=4;//默认速度
        self.pagingEnabled=YES;
        self.showsHorizontalScrollIndicator=NO;
        self.showsVerticalScrollIndicator=NO;
    }
    return self;
}
-(void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    labelShow =[[UILabel alloc]init];
    labelShow.text=@"";
    [self addSubview:labelShow];
}
-(void)initData:(NSString*)nsStrInfo
{
    nsStrContentInfo=nsStrInfo;
    if (labelShow)
    {
        labelShow.text=nsStrContentInfo;
        UIFont *font = [UIFont fontWithName:@"Arial" size:14];
        //设置一个行高上限
        CGSize size = CGSizeMake(1000,2000);
        //计算实际frame大小，并将label的frame变成实际大小
        CGSize labelsize = [labelShow.text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
        [labelShow setFont:font];
        labelShow.lineBreakMode = UILineBreakModeWordWrap;
        [labelShow setFrame:CGRectMake(0, 10, labelsize.width, labelsize.height)];
        //self.contentSize=CGSizeMake(labelsize.width* 2,0);
        self.blnInitData=YES;
    }
    
}
-(void)setTextColor:(UIColor*)color
{
    [labelShow setTextColor:color];
}
-(void)start
{
    [self stop];
    if (nsTimerMoveLab==nil)
    {
        nsTimerMoveLab = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(moveLab:) userInfo:nil repeats:YES];
    }
}
- (void)moveLab:(id)sender
{
    CGRect frame=labelShow.frame;
    frame.origin.x = frame.origin.x+_nsIntSpeed;
    if (frame.origin.x>self.frame.size.width)
    {
        frame.origin.x=-labelShow.frame.size.width;
    }
    [labelShow setFrame:frame];
}
- (void)stop
{
    if (nsTimerMoveLab)
    {
        [nsTimerMoveLab invalidate];
        nsTimerMoveLab=nil;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
